<template>
	<view>
		<view class="bg"></view>
		<view class="wrap">
			<view class="top">
				<view class="search" :style="{'margin-top':statusBarHeight+4+'px'}">
					<input type="text" v-model="keywords" placeholder="请输入商品名称">
					<uni-icons @click="init" type="search" color="#275DFE" size="20"></uni-icons>
				</view>
				<view class="score">
					<text>
						我的积分
					</text>
					<view class="num">
						{{score}}
						<view class="my" @click="goScore">
							积分明细
						</view>
					</view>
				</view>
				<image src="@/static/staff/icon1.png" mode=""></image>
			</view>
		</view>
		<view class="container">
			<view class="list">
				<view class="col" v-for="item in list" :key="item.goods_no" @click="goDetail(item)">
					<view class="item ">
						<image :src="item.image" mode=""></image>
						<view class="title">
							{{item.goods_name}}
						</view>
						<view class="price">
							{{item.price}}积分
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-load-more :status="status"></uni-load-more>
		<tabbar active='1'></tabbar>
	</view>
</template>

<script>
	import tabbar from "@/components/tabbar_staff.vue"
	export default {
		components: {
			tabbar
		},
		data() {
			return {
				list: [],
				page: 1,
				status: "no-more",
				score: '',
				statusBarHeight: null,
				keywords: ''
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res) => {
					this.statusBarHeight = res.statusBarHeight
				}
			});
		},
		onShow() {
			uni.hideHomeButton()
			this.init()
			this.getInfo()
		},
		onPullDownRefresh() {
			this.init()
		},
		onReachBottom() {
			this.page++
			this.getList()
		},
		methods: {
			init() {
				this.list = []
				this.page = 1
				this.getList()
			},
			getList() {
				this.status = "loading"
				this.$post("/goods/goods_data", {
					page: this.page,
					keywords: this.keywords
				}).then(res => {
					this.status = "no-more"
					uni.stopPullDownRefresh()
					this.list = this.list.concat(res.data.data)
				})
			},
			getInfo() {
				this.$post("/user/userinfo").then(res => {
					this.score = res.data.score
				})
			},
			goDetail(item) {
				uni.navigateTo({
					url: "./detail?goods_no=" + item.goods_no
				})
			},
			goScore() {
				uni.navigateTo({
					url: "/pages/staff/user/detail/detail"
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.bg {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 686rpx;
		background: linear-gradient(#3670F6 70%, transparent);
	}

	.top {
		position: relative;
		color: #fff;
		height: 350rpx;

		.search {
			width: calc(100% - 200rpx);
			background-color: #fff;
			height: 62rpx;
			line-height: 62rpx;
			border-radius: 30px;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 30rpx;

			input {
				font-size: 28rpx;
				width: calc(100% - 40rpx);
				color: #000;
			}
		}

		.score {
			height: calc(100% - 62rpx);
			display: flex;
			flex-direction: column;
			justify-content: center;

			text {
				color: #D9E4FF;
				font-size: 26rpx;
			}

			.num {
				font-size: 48rpx;
				margin-top: 20rpx;
				display: flex;
				align-items: center;

				.my {
					background: rgba(255, 255, 255, 0.2);
					border-radius: 22rpx;
					line-height: 44rpx;
					font-size: 24rpx;
					color: #FFFFFF;
					padding: 0 30rpx;
					margin-left: 40rpx;
				}
			}
		}

		image {
			position: absolute;
			width: 350rpx;
			height: 350rpx;
			right: -80rpx;
			top: 50rpx;
		}
	}

	.container {
		padding: 20rpx 34rpx;
		position: relative;

		.list {
			background-color: #fff;
			border-radius: 20rpx;
			padding: 20rpx;
			margin: -14rpx;
			display: flex;
			flex-wrap: wrap;

			.col {
				padding: 14rpx;
				width: 50%;

				.item {
					font-size: 26rpx;

					image {
						height: 280rpx;
						border-radius: 20rpx;
					}

					.title {
						font-weight: bold;
						padding: 16rpx 0;
					}

					.price {
						color: #FF5B5B
					}
				}
			}
		}
	}
</style>